﻿using DevExpress.XtraEditors;
using DevExpress.XtraTreeList.Nodes;
using MM.Commmon.UI;
using MM.Common.Base;
using MM.Common.DBBase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MM.Common.Support
{
    public partial class FrmModuleEdit : FrmBase
    {
        public FrmModuleEdit()
        {
            InitializeComponent();
        }


        private void btnExit_Click(object sender, EventArgs e)
        {
            base.DialogResult = DialogResult.Cancel;
            base.Close();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string text = this.txtModuleCode.Text;
            string paramValue = this.txtModuleName.Text;
            string str3 = this.txtModuleFileName.Text;
            string str4 = "N";
            if (this.ckIsValid.Checked)
            {
                str4 = "Y";
            }
            string str5 = this.meDescribe.Text;
            string commandtext = "UPDATE MXHLY_SYS_MODULE SET MODULE_NAME = :module_name ,VERSION = :version , MODULE_FILENAME = :mfile_name ,SERIAL = :serial ,USED_FLAG = :isvalid , UPDATE_TIME = SYSDATE ,UPDATE_EMP_ID = :operid ,DESCRIBE = :describe WHERE MODULE_CODE = :module_code";
            DataParamCol parms = new DataParamCol(new DataParam[] { new InputDataParam("module_name", paramValue), new InputDataParam("version", this.txtVersion.Text), new InputDataParam("mfile_name", str3), new InputDataParam("serial", this.txtSerial.Text), new InputDataParam("isvalid", str4), new InputDataParam("operid", SystemInfo.OperId), new InputDataParam("describe", str5), new InputDataParam("module_code", text) });
            if (SystemInfo.DbData.ExecuteSql(commandtext, parms) >= 0)
            {
                this.moduleNode.SetValue("CODE", text);
                this.moduleNode.SetValue("NAME", paramValue);
                this.moduleNode.SetValue("OBJECT_NAME", str3);
                this.moduleNode.SetValue("USED_FLAG", str4);
                this.moduleNode.SetValue("DESCRIBE", str5);
                base.DialogResult = DialogResult.OK;
                base.Close();
            }
            else
            {
                XtraMessageBox.Show("更新不成功！\n原因：" + SystemInfo.DbData.ErrorMessage, "出错", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            }
        }

        public bool SetParameter(TreeListNode node)
        {
            if (base.Init())
            {
                this.moduleNode = node;
                string paramValue = node.GetValue("CODE").ToString();
                DataTable dt = new DataTable();
                string commandtext = "SELECT MODULE_NAME ,VERSION ,MODULE_FILENAME ,FILE_TIME ,SERIAL ,USED_FLAG ,DESCRIBE FROM MXHLY_SYS_MODULE WHERE MODULE_CODE = :module_code";
                SystemInfo.DbData.Retrieve(commandtext, new DataParamCol(new DataParam[] { new InputDataParam("module_code", paramValue) }), ref dt);
                this.txtModuleCode.Text = paramValue;
                this.txtModuleName.Text = dt.Rows[0]["MODULE_NAME"].ToString();
                this.txtVersion.Text = dt.Rows[0]["VERSION"].ToString();
                this.txtModuleFileName.Text = dt.Rows[0]["MODULE_FILENAME"].ToString();
                this.txtFileTime.Text = dt.Rows[0]["FILE_TIME"].ToString();
                this.txtSerial.Text = dt.Rows[0]["SERIAL"].ToString();
                this.ckIsValid.Checked = dt.Rows[0]["USED_FLAG"].ToString() == "Y";
                this.meDescribe.Text = dt.Rows[0]["DESCRIBE"].ToString();
                return true;
            }
            return false;
        }
    }
}
